package com.mo.lib.ui.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import java.lang.reflect.ParameterizedType

/**
 * @ author：mo
 * @ data：2021/9/23:17:24
 * @ 功能：https://blog.csdn.net/weixin_57207173/article/details/118787293
 */
abstract class BaseVbmFragment<VB : ViewDataBinding,VM: ViewModel>() : BaseVbFragment<VB>() {

    lateinit var viewModel: VM
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val superclass = javaClass.genericSuperclass
        val vmClass = (superclass as ParameterizedType).actualTypeArguments[1]as Class<VM>
        viewModel= ViewModelProvider(this).get(vmClass);
        return super.onCreateView(inflater, container, savedInstanceState)
    }
}
